package cn.xiangxiang.controller.goods;

import cn.xiangxiang.pojo.common.Result;
import cn.xiangxiang.pojo.goods.Category;
import cn.xiangxiang.service.goods.CategoryService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Reference
    private CategoryService categoryService;

    @RequestMapping("/findall")
    public List<Category> findAll(){
        return categoryService.list();
    }

    @PostMapping("/findconditionpage")
    public Page<Category> findConditionPage(Integer startpage, Integer pagesize, @RequestBody Category category){
        return  categoryService.findConditionPage(startpage,pagesize,category);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Category category){
        categoryService.save(category);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Category category){
        categoryService.updateById(category);
        return new Result();
    }

    @GetMapping("/delbyid")
    public Result delById(Integer id){
        categoryService.delById(id);
        return new Result();
    }

    @GetMapping("/findbyid")
    public Category findById(Integer id){
        return categoryService.getById(id);
    }

    @GetMapping("/findcategorymenu")
    public List<Map<String, Object>> findCategoryMenu(){
        return categoryService.findCategoryMenu();
    }
}
